// pages/userInfo/userInfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked: false,
    popBgShow: false,
    formList: [{
      formType: 'input',
      id: 0,
      must: true,
      title: '姓名',
      inputType: 'text',
      val: '',
      showError: false,
      errorText: '请填写体检人的姓名'
    }, {
      formType: 'picker',
      id: 1,
      must: true,
      mode: 'selector',
      title: '证件类型',
      array: ['身份证', '士官证', '学生证', '驾驶证', '护照', '港澳通行证'],
      index: 0
    }, {
      formType: 'input',
      id: 2,
      must: true,
      title: '证件号码',
      inputType: 'number',
      val: '',
      showError: false,
      errorText: '请填写体检人的证件号码'
    }, {
      formType: 'picker',
      id: 3,
      must: true,
      mode: 'selector',
      title: '性别',
      array: ['男', '女'],
      index: 0
    }, {
      formType: 'picker',
      id: 4,
      must: true,
      mode: 'date',
      title: '生日',
      date: '',
      showError: false,
      errorText: '请选择体检人的生日'
    }, {
      formType: 'picker',
      id: 5,
      must: true,
      mode: 'selector',
      title: '婚否',
      array: ['未婚', '已婚'],
      index: 0
    }, {
      formType: 'input',
      id: 6,
      must: true,
      title: '手机号',
      val: '',
      inputType: 'number',
      showError: false,
      errorText: '请填写体检人的手机号'
    }, {
      formType: 'input',
      id: 7,
      must: false,
      title: '邮箱',
      val: '',
      inputType: 'text',
    }],
  },
  bindKeyInput: function(e) {
    let id = e.currentTarget.id,
      list = this.data.formList,
      value = e.detail.value;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        list[i].val = value;
      }
    }
    this.setData({
      formList: list
    })
  },
  bindPickerChange: function(e) {
    let id = e.currentTarget.id,
      list = this.data.formList;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        if (list[i].mode == 'date') {
          list[i].date = e.detail.value
        } else {
          list[i].index = e.detail.value
        }
      }
    }
    this.setData({
      formList: list
    })
  },
  clearInput: function(e) {
    let id = e.currentTarget.id,
      list = this.data.formList;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        list[i].val = ""
      }
    }
    this.setData({
      formList: list
    })
  },
  formNext: function(e) {
    let list = this.data.formList;
    for (let i = 0; i < list.length; i++) {
      if (list[i].val == '' && list[i].must) {
        list[i].showError = true;
      }
    }
    this.setData({
      formList: list
    })
  },
  agree: function (e) {
    this.setData({
      checked: true,
      popBgShow: false,
    })
  },
  showPop: function (e) {
    this.setData({
      popBgShow: true,
    })
  },
  closePop: function (e) {
    this.setData({
      popBgShow: false,
    })
  }
})